package com.Servlet;

import com.Service.Impl.UserServiceImpl;
import com.Service.UserService;
import com.entity.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author: 冷俊杰
 * @Description: 注册用户
 * @DateTime: 2022/6/22 19:44
 **/
@WebServlet("/insertUser")
public class insertUser extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        UserService service = new UserServiceImpl();
        String sessionCode = request.getParameter("codes");
        System.out.println(sessionCode);
        if (sessionCode != null && sessionCode!="") {
            String phone = request.getParameter("phone");
            String username = request.getParameter("username");
            String password = request.getParameter("password");
            int i = service.insertUser(new User(phone, username, password));
            if (i != 0) {
                request.getRequestDispatcher("./register.jsp").forward(request, response);
            } else {
                request.getRequestDispatcher("./remainYH.jsp").forward(request, response);
            }
        } else {
            request.getRequestDispatcher("./remainYH.jsp").forward(request, response);
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
